<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <title>Purchase</title>
    </head>
    <body>
        <div id="container">
            <jsp:include page="includes/header.html" />
            <div class="main">
                <div class="services">
                    <div class="service_bg">
                        <h3>Member Center</h3>
                        <ul class="link">
                            <li>You can search or purchase sections on page <a href="index.do"><strong>Purchase</strong></a>.</li>
                            <li>You can also check out your loyalty point on page <a href="memberViewLoyaltyPoint.do"><strong>loyalty point</strong></a>.</li>
                            <li>If you want to refund some sections you have purchased, please go to <a href="memberRefund.do"><strong>Refund</strong></a></li>
                            <li>If you want to log out, please <a href="logout.do"><strong>log out</strong></a>.</li>
                        </ul>
                        <div class="clr"></div>
                        <div class="service_bg">
                            <h3>About the authors</h3>
                            <p><img src="images/user_pic.jpg" width="63" height="63" hspace="5" align="left" alt="picture" /><a href="#"><strong>ZHANG Niantong</strong></a><br />
                                Department of Computer Science, City University of Hong Kong</p>
                            <p><img src="images/user_pic.jpg" width="63" height="63" hspace="5" align="left" alt="picture" /><a href="#"><strong>ZHANG Hao</strong></a><br />
                                Department of Computer Science, City University of Hong Kong</p>
                        </div></div>
                    <div class="clr"></div>
                </div>
                <div class="global_main">
                    <div class="page_title_text">
                        <h1>Sections waiting for payment</h1>
                        <div class="clr"></div>
                          <%
                    if (session.getAttribute("errorMessage") != null) {
                        out.print("<h2>&nbsp;&nbsp;&nbsp;&nbsp;<strong><span style='color:red;'>Error: " + session.getAttribute("errorMessage") + "</span> </strong></h2>");
                        session.setAttribute("errorMessage", null);
                    }
                    List<Purchase> listPurchase = (List<Purchase>) session.getAttribute("listPurchase");
       				if (listPurchase.size()!=0)
       				{
                    %>
        <table class="movieTable">
            <thead>
                <tr>
                    <th>Movie Name</th>
                    <th>Start Time</th>
                    <th>House</th>
                    <th>Seat No</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <%@ page import="java.util.List"%>
                <%@ page import="model.MovieSection"%>
                <%@ page import="model.Purchase"%>
                <%
                          
                            session.setAttribute("listPurchase", null);
                            List<MovieSection> listMovieSection = (List<MovieSection>) session.getAttribute("listMovieSection");
                            session.setAttribute("listMovieSection", null);
                            for (int i = 0; i < listPurchase.size(); i++) {
                                pageContext.setAttribute("purchase", listPurchase.get(i));
                                pageContext.setAttribute("movieSection", listMovieSection.get(i));
                %>
                <tr>
                    <td>${movieSection.movieName}</td>
                    <td>${movieSection.startTimeString}</td>
                    <td>${movieSection.houseId}</td>
                    <td>${purchase.purchaseId.seatNo}</td>
                    <td>
                        <a
                            href="memverViewUnpaid.do?action=payment&movieSectionId=${movieSection.id}&seatNo=${purchase.purchaseId.seatNo}">Pay</a>
                    </td>
                </tr>
                <%
                            }
                %>
            </tbody>
        </table>
        <%
       				}
       				else{
        %>
        		<h2 style="margin-left:30px;">There is no section need to be paid!</h2>
        		<% 
        	}
                %>
        </div>
                </div>
                <div class="clr"></div>
            </div>
            <jsp:include page="includes/footer.html" />
        </div>
    </body>
</html>